//
//  MainView.m
//  悠狸
//
//  Created by Grant on 15/8/31.
//  Copyright (c) 2015年 Dung. All rights reserved.
//

#import "MainView.h"
#import "SecondCategories.h"
#import "UIImageView+WebCache.h"
@interface MainView ()

@property (nonatomic, retain) UIImageView *myImageView;
@property (nonatomic, retain) UILabel *myTitleLabel;

@end

@implementation MainView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self create];
    }
    return self;
}

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    [self.delegate didSelectedMainViewWithSecondCategory:self.secCategory];
}
- (void)create
{
    self.myImageView = [[[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.frame.size.width, (self.frame.size.height / 5 * 4)*OffHeight)] autorelease];
    [self addSubview:_myImageView];
    
    self.myTitleLabel = [[[UILabel alloc] initWithFrame:CGRectMake(0, _myImageView.frame.size.height, self.frame.size.width, (self.frame.size.height / 5)*OffHeight)] autorelease];
    [self addSubview:_myTitleLabel];
    _myTitleLabel.font = [UIFont systemFontOfSize:12];
    _myTitleLabel.textAlignment = NSTextAlignmentCenter;
}

- (void)sendSecCategory:(SecondCategories *)secCategory
{
    self.secCategory = secCategory;
    self.myTitleLabel.text = secCategory.name;
    [self.myImageView sd_setImageWithURL:[NSURL URLWithString:secCategory.icon_url]];
}

@end
